﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    @Html.Partial("ViewLibrary")
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <link href="~/Content/Styles/Order.css" rel="stylesheet" />
    <title>Index</title>
        <script>
            $(document).ready(function () {
                GetMer();
                InitPower();//加载权限
            });

            var UserIntID;//定义用户积分ID
            var Mer;//商户ID
            var diplayText;//商户名称

            //获取商户
            function GetMer() {
                var grid = $('#SelectMerID').combogrid({
                    panelWidth: 500,
                    idField: 'MerID',
                    textField: 'MerName',
                    url: '/UserMerchantsManage/InitMerID',
                    method: 'post',
                    pageSize: 5,
                    pageList: [5],
                    pagination: true,
                    rownumbers: true,
                    fitColumns: true,
                    columns: [[
                        { field: 'MerID', title: '商户ID', width: 80, align: 'center' },
                        { field: 'MerName', title: '商户名称', width: 80, align: 'center' },
                        { field: 'MerTxt', title: '商户介绍', width: 120, align: 'center' },
                        { field: 'MerAdr', title: '商户地址', width: 80, align: 'center' },
                        { field: 'MerCall', title: '商户联系电话', width: 80, align: 'center' }
                    ]],
                    onSelect: function (index, row) {
                        //alert(1);
                        diplayText = row[grid.combogrid('options').textField];//获取商户名称
                        //alert(diplayText)
                        Mer = $('#SelectMerID').combogrid("getValue");//获取操作员
                        //alert(Mer)
                        //加载对应订单
                        InitTable(Mer);
                        Dep();//加载组织结构
                    },
                    onLoadSuccess: function () {
                        //分页后判断下是否有选中的数据行，combogrid会依据上一次选中的值进行初始化，选中datagrid数据行和设置显示值
                        if (!grid.combogrid('grid').datagrid('getSelected'))//不在当前页
                        {
                            $('#SelectMerID').combogrid("setValue", diplayText);
                        }
                    }
                });
            }

            //部门选择
            function Dep() {
                $('#SearchDepID').combotree({
                    url: '/UserPlatformManage/getDep',
                    method: 'get',
                    multiple: false,
                });
            }

            // 加载表格
            function InitTable(MerID) {
                $('#tab').datagrid({
                    fitColumns: true,   // 自动列宽
                    autoRowHeight: false,   // 自动行高
                    fitColumns: true,   // 自动宽度
                    striped: true,  // 是否显示虚线
                    nowrap: false,   // 一行数据单行显示
                    pagination: true,   // 显示分页导航栏
                    rownumbers: false,  // 显示系统行号
                    singleSelect: true, // 只允许选择一行
                    sortOrder: 'desc',    // 排序方式
                    url: '/UserMerchantsManage/InitTable?MerID='+MerID,    // 数据加载的地址
                    method: 'post',  // 请求方法
                    loadMsg: '正在加载数据 ...',  // 提示信息
                    columns: [[
                        { title: '编号', field: 'AccID', align: 'center', sortable: true, hidden: true },
                        { title: '账号', field: 'AccNum', align: 'center', sortable: true },
                        {
                            title: '性别', field: 'AccSex', align: 'center', sortable: true, formatter: function (value, row, index) {
                                if (value == 0) {
                                    return "男";
                                } else {
                                    return "女";
                                }
                            }
                        },
                        { title: '姓名', field: 'AccName', align: 'center', sortable: true },
                        { title: '个人编号', field: 'AccIdentifier', align: 'center', sortable: true },
                        {
                            title: '用户身份', field: 'IdentityID', align: 'center', sortable: true, formatter: function (value, row, index) {
                                if (value) {
                                    return row.IdentityID_DiName_SystemIdentity;
                                } else {
                                    return value;
                                }
                            }
                        },
                        {
                            title: '用户类别', field: 'CategoryID', align: 'center', sortable: true, formatter: function (value, row, index) {
                                if (value) {
                                    return row.CategoryID_DicName_SystemIdentity;
                                } else {
                                    return value;
                                }
                            }
                        },
                        { title: '手机号', field: 'AccCall', align: 'center', sortable: true },
                        {
                            title: '证件类型', field: 'AccCerType', align: 'center', sortable: true, formatter: function (value, row, index) {
                                if (value) {
                                    return row.AccCerType_DicName_Login;
                                } else {
                                    return value;
                                }
                            }
                        },
                        { title: '证件号', field: 'AccCerNub', align: 'center', sortable: true },
                        {
                            title: '组织结构', field: 'DepID_DepName_Department', align: 'center', sortable: true
                        },
                        {
                            title: '用户状态', field: 'SataeID', align: 'center', sortable: true, formatter: function (value, row, index) {
                                if (value) {
                                    return row.StateID_DicName_SystemIdentity;
                                } else {
                                    return value;
                                }
                            }
                        }
                    ]],
                    toolbar: '#tb1',
                });
            }

            // 表单提交
            function OnSubmit() {
                var topup = $('#IntNub').textbox('getValue')
                if (topup == null || topup == 0) {
                    $.messager.alert("提示", "请输入正确的数字");
                    return;
                }
                var BZ = $('#BZ').val();
                if (BZ == "") {
                    $.messager.alert("提示", "请输入充正备注");
                    return;
                }
                var postdata = {
                    UserIntID: UserIntID,//用户钱包ID
                    updateInt: topup,//变更金额
                    BZ: BZ,//备注
                };
                $.post("/UserMerchantsManage/BtnEdit", postdata, function (date) {
                    if (date == "1") {
                        $("#editDialog").dialog('close');
                        $("#tab").datagrid('reload');
                    }
                    else {
                        $.messager.alert("友情提示", "修改失败，请检查");
                    }
                });
            }
            // 编辑
            function BtnEdit() {
                var UpdateInfoID = $("#tab").datagrid("getSelections");   // 获得选中行
                if (UpdateInfoID.length == 1) {
                    //显示充值、提取、冲正功能
                    $("#tr1").show();
                    $("#tr2").show();
                    $("#tr3").show();
                    $("#tr4").show();
                    $("#tr5").show();
                    $("#tr6").show();
                    document.getElementById("editDialog").style.height = "400px";
                    $("#editDialog").dialog("open").dialog("setTitle", "用户商户积分编辑");
                    BingUpdate();

                }
                else {
                    $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
                }
            }
            // 详细
            function BtnDet() {
                var UpdateInfoID = $("#tab").datagrid("getSelections");   // 获得选中行
                if (UpdateInfoID.length == 1) {
                    //隐藏充值、提取、冲正功能
                    $("#tr1").hide();
                    $("#tr2").hide();
                    $("#tr3").hide();
                    $("#tr4").hide();
                    $("#tr5").hide();
                    $("#tr6").hide();
                    document.getElementById("editDialog").style.height = "270px";
                    $("#editDialog").dialog("open").dialog("setTitle", "用户平台积分明细");
                    BingUpdate();
                }
                else {
                    $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
                }
            }
            // 刷新
            function BtnRef() {
                $('#tab').datagrid('reload');
            }
            // 搜索
            function BtnSearch() {
                var SearchAccName = $('#SearchAccName').val();
                var SearchAccCall = $('#SearchAccCall').val();
                var SearchAccIdentifier = $('#SearchAccIdentifier').val();
                var SearchAccCerNub = $('#SearchAccCerNub').val();
                var SearchDepID = $('#SearchDepID').combotree('getValue');
                $('#tab').datagrid({
                    url: '/UserMerchantsManage/SeachTable?MerID=' + Mer + "&SearchAccName=" + SearchAccName + "&SearchAccCall=" + SearchAccCall + "&SearchAccIdentifier=" + SearchAccIdentifier +
                    "&SearchAccCerNub=" + SearchAccCerNub + "&SearchDepID=" + SearchDepID,
                });
            }
            // 权限
            function InitPower() {
                var powe = $('#UserPowers').val();   // 权限集合
                if (powe.indexOf("") == -1) {    // 增加
                    document.getElementById("BtnEdit").style.display = "none";
                }
            }

            //给商品订单编辑界面赋值
            function BingUpdate() {
                var checkdata = $("#tab").datagrid("getSelections")[0];
                if (checkdata != null) {
                    UserIntID = checkdata.UserIntID;
                    $("#AccName").textbox('setValue', checkdata.AccName);
                    var Sex;
                    if (checkdata.AccSex == 0) {
                        Sex = "男";
                    }
                    else {
                        Sex = "女";
                    }
                    $("#AccSex").textbox('setValue', Sex);
                    $("#AccCall").textbox('setValue', checkdata.AccCall);
                    $("#AccIdentifier").textbox('setValue', checkdata.AccIdentifier);
                    $("#AccCerType").textbox('setValue', checkdata.AccCerType_DicName_Login);
                    $("#AccCerNub").textbox('setValue', checkdata.AccCerNub);
                    $("#DepID_DepName_Department").textbox('setValue', checkdata.DepID_DepName_Department);
                    $("#IdentityID_DiName_SystemIdentity").textbox('setValue', checkdata.IdentityID_DiName_SystemIdentity);
                    $("#StateID_DicName_SystemIdentity").textbox('setValue', checkdata.StateID_DicName_SystemIdentity);
                    $("#IntNowNub").textbox('setValue', checkdata.IntNowNub);
                    $("#IntAllNub").textbox('setValue', checkdata.IntAllNub);
                    $("#IntConNub").textbox('setValue', checkdata.IntConNub);
                    $("#diplayText").textbox('setValue', diplayText);
                    $("#IntNub").textbox('setValue', "");
                    $('#BZ').val("");
                }
            }

            // 查看商户下的全部用户商户积分
            function Whole() {
                Mer = $('#SelectMerID').combogrid("getValue");//获取操作员
                //alert(Mer)
                //加载对应订单
                InitTable(Mer);
                Dep();//加载组织结构
            }

            // 清除搜索栏内容
            function SearchClear() {
                $('#SearchAccName').textbox('setValue', "");
                $('#SearchAccCall').textbox('setValue', "");
                $('#SearchAccIdentifier').textbox('setValue', "");
                $('#SearchAccCerNub').textbox('setValue', "");
            }
    </script>
</head>
<body>
     <div style="padding:5px; background-color:#F4F4F4">
        <div >
            <a>商户：</a>
            <input id="SelectMerID" class="easyui-combogrid" style="width: 120px" />
        </div>
    </div>
    <div>
        <table id="tab" style="margin: 0px; padding: 0px;"></table>
    </div>
    <div id="tb1"style="background-color:#F4F4F4">
        <div style="padding-top:2px">
         <button id="BtnEdit" onclick="BtnEdit()" class="easyui-linkbutton" data-options="iconCls:'icon-edit'">编辑</button>
        <button id="BtnDet" onclick="BtnDet()" class="easyui-linkbutton" data-options="iconCls:'icon-help'">详细</button>
        <button id="BtnRef" onclick="BtnRef()" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">刷新</button>
        <button id="Whole" onclick="Whole(), SearchClear()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">查看全部</button>
        </div>
        <div style="padding-top:2px">
        <b>姓名: </b> 
        <input class="easyui-textbox" type="text" id="SearchAccName" name="SearchAccName" style="width: 100px;" />
        <b>手机号: </b> 
        <input class="easyui-textbox" type="text" id="SearchAccCall" name="SearchAccCall" style="width: 100px;" />
        <b>个人编号: </b> 
        <input class="easyui-textbox" type="text" id="SearchAccIdentifier" name="SearchAccIdentifier" style="width: 100px;" />
        @* <b>证件类型: </b> *@
        @*<input class="easyui-textbox" type="text" id="SearchAccCerType" name="SearchAccCerType" style="width: 100px;" />*@
       @* @Html.DropDownList("SearchAccCerType", @ViewBag.AccCerTypeList as List<SelectListItem>, new { @class = "easyui-combobox", name = "SearchAccCerType", style="width: 100px;" })*@
        <b>证件号: </b> 
        <input class="easyui-textbox" type="text" id="SearchAccCerNub" name="SearchAccCerNub" style="width: 100px;" />
        <b>组织结构: </b> 
        <input class="easyui-textbox" type="text" id="SearchDepID" name="SearchDepID" style="width: 200px;" />
        @*@Html.DropDownList("SearchDepID", @ViewBag.DepIDList as List<SelectListItem>, new { @class = "easyui-combobox", name = "SearchDepID", style="width: 100px;" })*@
        <button id="BtnSearch" onclick="BtnSearch()" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</button>
    </div>
        @*<b>商户: </b><select id="SelectMerID" name="SelectMerID" style="width: 200px;"></select>*@
       
    </div>
    @*<hr />*@
    
    
    <div id="dia"></div>
    <input type="hidden" id="UserPowers" name="UserPowers" value="@ViewBag.UserPowers" />
     <div id="editDialog" class="easyui-dialog" style="width:700px; padding: 10px; padding: fixed; top: 5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            <div style="padding-top: 10px">
                <table cellpadding="2" id="tbledit" style="width: 100%; height: 100%;">
                    <tr>
                        <td width="90" class="userinfo-td-l">姓名：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="AccName" name="AccName" readonly="true" />
                        </td>
                        <td width="20"></td>
                        <td class="userinfo-td-l">性别：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="AccSex" name="AccSex" readonly="true" />
                        </td>
                    </tr>
                    <tr></tr>
                    <tr>
                        <td class="userinfo-td-l">手机号：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="AccCall" name="AccCall" readonly="true" /></td>
                        <td></td>
                        <td class="userinfo-td-l">个人编号：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="AccIdentifier" name="AccIdentifier" readonly="true" />
                        </td>
                    </tr>
                    <tr></tr>
                    <tr>
                        <td class="userinfo-td-l">证件类型：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="AccCerType" name="AccCerType" readonly="true" />
                        </td>
                        <td></td>
                        <td class="userinfo-td-l">证件号：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="AccCerNub" name="AccCerNub" readonly="true" />
                        </td>
                    </tr>
                    <tr></tr>
                    <tr>
                        <td class="userinfo-td-l">部门：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="DepID_DepName_Department" name="DepID_DepName_Department" readonly="true" />
                        </td>
                        <td></td>
                        <td class="userinfo-td-l">身份：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="IdentityID_DiName_SystemIdentity" name="IdentityID_DiName_SystemIdentity" readonly="true" />
                        </td>
                    </tr>
                    <tr></tr>
                    <tr>
                        <td class="userinfo-td-l">状态：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="StateID_DicName_SystemIdentity" name="StateID_DicName_SystemIdentity" readonly="true"></input>
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr style="height: 5px"></tr>
                    <tr>
                        <td colspan="5">
                            <hr style="border: dashed; border-top: 5px; color: rgb(184, 224, 242);" />
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr style="height: 5px"></tr>
                    <tr>
                        <td class="userinfo-td-l">积分商户：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="diplayText" name="diplayText" readonly="true"/>
                        </td>
                        <td></td>
                        <td class="userinfo-td-l">剩余积分：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="IntNowNub" name="IntNowNub" readonly="true" />分
                        </td>
                    </tr>
                    <tr></tr>
                    <tr>
                        <td class="userinfo-td-l">历史累计积分：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="IntAllNub" name="IntAllNub" readonly="true" />分
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr></tr>
                    <tr >
                        <td class="userinfo-td-l">历史消耗积分：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="IntConNub" name="IntConNub" readonly="true">分</input>
                        </td>
                        <td></td>
                        <td class="userinfo-td-r">
                            @*<a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" id="Recharge" onclick="OnSubmit(0)">确认</a>*@
                        </td>
                        <td class="userinfo-td-l"></td>
                    </tr>
                    <tr style="height: 5px"></tr>
                    <tr id="tr1">
                        <td colspan="5">
                            <hr style="border: dashed; border-top: 5px; color: rgb(184, 224, 242);" />
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr style="height: 5px"></tr>
                    <tr id="tr2">
                        <td class="userinfo-td-l">积分修改：</td>
                        <td class="userinfo-td-r">
                            <input class="easyui-textbox" type="text" id="IntNub" name="IntNub">分</input>
                        </td>
                        <td></td>
                        <td class="userinfo-td-r">
                        </td>
                        <td></td>
                    </tr>
                    <tr id="tr3"></tr>
                    <tr id="tr4">
                        <td class="userinfo-td-l">备注：</td>
                        <td class="userinfo-td-r" colspan="4">
                            <textarea class="easyui-textarea" style="width: 500px" rows="5" type="text" id="BZ" name="BZ"></textarea></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr id="tr5"></tr>
                    <tr id="tr6">
                        <td colspan="5" align="center">
                            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-ok" id="ok" onclick="OnSubmit()">确认</a>
                        </td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
</body>
</html>
